//
// Created by liushuai on 2021/2/14.
//

#include "canConstruct.h"

bool canConstruct(string ransomNote, string magazine) {
    map<char, int> freq;
    for (auto chars:magazine) {
        if (freq.count(chars))
            freq[chars] += 1;
        else
            freq[chars] = 1;
    }
    for (auto e:ransomNote) {
        if (freq.count(e)) {
            freq[e] -= 1;
            if (freq[e] < 0)
                return false;
        } else
            return false;

    }
    return true;
}